﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization;
using Galaxy.ModuleInterface.Messages.Destination;
using System.Net;
using Galaxy.ModuleInterface;

namespace Galaxy.Portal.Messages
{
    [Serializable]
    public class CNetDestination : CDestination, INetDestination
    {
        private IPAddress f_IP;

        private int f_Port;

        public IPAddress Address { get { return f_IP; } }

        public int Port { get { return f_Port; } }


        public CNetDestination(IPAddress Address, int Port, IGalaxyModule Module)
            : base(Module) { f_IP = Address; f_Port = Port; }

        public CNetDestination(IPAddress Address, int Port, params IGalaxyModule[] Modules)
            : base(Modules) { f_IP = Address; f_Port = Port; }

        public CNetDestination(IPAddress Address, int Port, params string[] Modules)
            : base(Modules) { f_IP = Address; f_Port = Port; }

        protected CNetDestination(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
            f_IP = info.GetValue("Address", typeof(IPAddress)) as IPAddress;
            f_Port = info.GetInt32("Port");
        }

        public override bool Check(IGalaxyModule Module)
        {
            return base.Check(Module) || Module is IPortal;
        }

        public override int GetHashCode()
        {
            // Внимание! Определить метод!
            return base.GetHashCode();
        }

        public override bool Equals(object obj)
        {
            if(obj is IGalaxyModule) return Check(obj as IGalaxyModule);
            return base.Equals(obj);
        }

        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            base.GetObjectData(info, context);
            info.AddValue("Address", f_IP);
            info.AddValue("Port", f_Port);
        }

        
    }
}
